import { axios } from '@/utils/request'
import { mimeMap, resolveBlob } from '@/utils/download'

const api = {
    questionList: '/system/form/question/sys/list',
    resultTitleList: '/system/form/question/sys/detailTitle/',
    resultList: '/system/form/question/sys/detail/',
    updateStatus: '/system/form/question/sys/status/',
    questionCreate: '/system/form/question/sys/create',
    questionInfo: '/system/form/question/sys/info/',
    send: '/system/form/question/sys/send',
    exportList: '/system/form/question/exportExcel',
    qrCode: '/system/form/question/sys/createQrcode'
}

export default api

/**
  * 问卷列表
  */
export function questionList(data) {
    return axios({
        url: api.questionList + `?current=${data.current}&size=${data.pageSize}`,
        method: 'post',
        data
    })
}

/**
  * 问卷结果标题列表
  */
export function resultTitleList(id) {
    return axios({
        url: api.resultTitleList + id,
        method: 'get'
    })
}

/**
  * 问卷结果列表
  */
export function resultList(data) {
    return axios({
        url: api.resultList + data.id + `?current=${data.current}&size=${data.pageSize}`,
        method: 'get'
    })
}

/**
  * 问卷状态修改
  */
export function updateStatus(data) {
    let { id, status } = data
    return axios({
        url: api.updateStatus + `${id}/${status}`,
        method: 'get'
    })
}

/**
  * 问卷创建
  */
export function questionCreate(data) {
    return axios({
        url: api.questionCreate,
        method: 'post',
        data
    })
}

//问卷详情
export function questionInfo(id) {
    return axios({
        url: api.questionInfo + id,
        method: 'get'
    })
}

//问卷推送
export function send(data) {
    return axios({
        url: api.send,
        method: 'post',
        data
    })
}

/**
* 导出
*/
export function exportList(data) {
    axios({
        url: api.exportList + '/' + data.id,
        method: 'get',
        responseType: 'blob',
        data
    }).then(res => {
        resolveBlob(res, mimeMap.xlsx)
    })
}

//问卷详情
export function qrCode(id) {
    return axios({
        url: api.qrCode + '/' + id,
        method: 'get'
    })
}